const Express = require("express");
const RecordService = require("../../service/record");
const ResponseHelper = require("../ResponseHelper");
const router = Express.Router();

router.get("/list", async (req, res) => {
  try {
    const result = await RecordService.getRecordList();
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});
router.post("/query", async (req, res) => {
  try {
    const params = req.body;
    const result = await RecordService.getRecordListByQuery(params);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});
router.post("/add", async (req, res) => {
  try {
    const result = await RecordService.addRecord(req.body);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});
router.post("/update/:id", async (req, res) => {
  const Id = req.params.id;
  const Obj = req.body;
  try {
    const result = await RecordService.updateRecord(Id, Obj);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});
router.post("/del/:id", async (req, res) => {
  try {
    const Id = req.params.id;
    const result = await AlarmServer.deleteRecord(Id);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});


module.exports = router